package model;

import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Random;
import java.util.Scanner;

public class Country {
	
	private static Country country=new Country();
	
	ArrayList<City> cities=new ArrayList<City>();
	
	private Country() {};
	
	static public Country getIns(){
		return country;
	}
	
	
	public int size() {
		return cities.size();
		
	}
	
	public ArrayList<City> getCities() {
		return cities;
	}

	public void setCities(ArrayList<City> cities) {
		this.cities = cities;
	}

	public City getCity(int i) {
		return cities.get(i);
	}
	
	public double calcDistance(int i, int j) {
		City city1=cities.get(i);
		City city2=cities.get(j);
		
		double xDist=city1.getxPos()-city2.getxPos();
		double yDist=city1.getyPos()-city2.getyPos();
		double dist=Math.sqrt(Math.pow(xDist, 2)+Math.pow(yDist,2));
		return dist;
		
	}

	public void resetCities() {
		Random rand=new Random();
	/*	
		cities.add(new City(1, 5, 2));
		cities.add(new City(2, 7, 4));
		cities.add(new City(3, 8, 4));
		cities.add(new City(4, 8, 5));
		cities.add(new City(5, 5, 0));
		
		*/
//		for (int i = 0; i < 7; i++) {
//			City city=new City(i,rand.nextDouble()*10,rand.nextDouble()*10);
//			cities.add(city);
//		}
		try {
			Scanner scan= new Scanner(new File("tsp.txt"));
			int i=1;
			while(scan.hasNext()){
				int x=scan.nextInt();
				int y=scan.nextInt();
				cities.add(new City(i,x,y));
				i++;
			}
		} catch (FileNotFoundException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
			System.err.println("missing file \"tsp.txt\"");
			
		}
		
	}

	
	@Override
	public String toString() {
		return cities.toString();
	}

}
